package com.ushio.gougouwangguo.controller;

import com.ushio.commonmodule.pojo.result.Result;
import com.ushio.gougouwangguo.entity.mysql.UserMaterials;
import com.ushio.gougouwangguo.entity.qo.UserMaterialsByIdQo;
import com.ushio.gougouwangguo.entity.vo.UserMaterialsVo;
import com.ushio.gougouwangguo.service.IUserMaterialsService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 用户资源表 前端控制器
 * </p>
 *
 * @author 张文凯
 * @since 2025-09-23
 */
@RestController
@RequestMapping("/userMaterials")
@Tag(name="UserMaterials",description = "用户资源表")
public class UserMaterialsController {

    @Autowired
    IUserMaterialsService iUserMaterialsService;

    @GetMapping
    public Result<List<UserMaterialsVo>> getUserMaterials(@RequestParam() Long userId){
        try{
            List<UserMaterialsVo> list =  iUserMaterialsService.getUserMaterials(userId);
            return Result.success(list);
        }catch (Exception e){
            e.printStackTrace();
           return Result.fail();

        }
    }
    @GetMapping("/room")
    public Result<UserMaterialsVo> getRoom(){
        try{
            UserMaterialsVo list =  iUserMaterialsService.getRoom();
            return Result.success(list);
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail();

        }
    }

    @PostMapping("/id")
    public Result<List<UserMaterialsVo>> getUserMaterialsByid(@RequestBody UserMaterialsByIdQo userMaterialsByIdQo){
        try{
            List<UserMaterialsVo> list =  iUserMaterialsService.getUserMaterialsByid(userMaterialsByIdQo);
            return Result.success(list);
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail();

        }
    }


}
